package Pattern.AdapterPattern.program3;

class Client {
    public static void main(String[] args) {
        Dog dog = new DogLearn("狗");
        Cat cat = new CatLearn("猫");
        dog.Cry();
        cat.CatchMouse();
        System.out.println("----------------");
        Adapter adapter = new Adapter(dog,cat);
        adapter.Cry();
        adapter.CatchMouse();

    }

    interface Cat {
        void CatchMouse();
    }

    interface Dog {
        void Cry();
    }

    static class CatLearn implements Cat{
        private String cat;

        public CatLearn(String cat) {
            this.cat = cat;
        }

        @Override
        public void CatchMouse() {
            System.out.println(cat+"会抓老鼠");
        }
    }

    static class DogLearn implements Dog{
        private String dog;

        public DogLearn(String dog) {
            this.dog = dog;
        }

        @Override
        public void Cry() {
            System.out.println(dog+"会叫");
        }
    }

    static class Adapter implements Dog,Cat{
        Dog dog;
        Cat cat;

        public Adapter(Dog doget, Cat catet) {
            this.dog = doget;
            this.cat = catet;
        }

        @Override
        public void CatchMouse() {
            dog.Cry();
        }

        @Override
        public void Cry() {
            cat.CatchMouse();
        }
    }
}
